<template>
  <div class="ma-content-block">
	  <a-tabs v-model="activeTab" @change="handleTabChange" v-if="false">
	    <a-tab-pane key="zh" title="中文"></a-tab-pane>
	    <a-tab-pane key="en" title="英文"></a-tab-pane>
	    <a-tab-pane key="ja" title="日语"></a-tab-pane>
	    <a-tab-pane key="ko" title="韩语"></a-tab-pane>
	  </a-tabs>
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="预约项目" field="project_id">
            <a-input v-model="searchForm.project_id" placeholder="请输入预约项目" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="预约人" field="reservation_person">
            <a-input v-model="searchForm.reservation_person" placeholder="请输入预约人" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="身份证号" field="id_number">
            <a-input v-model="searchForm.id_number" placeholder="请输入身份证号" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="手机号" field="phone_number">
            <a-input-number v-model="searchForm.phone_number" placeholder="请输入手机号" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="预约时间" field="reservation_time">
            <a-date-picker  v-model="searchForm.reservation_time" placeholder="请输入预约时间" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="审核状态" field="status">
			   <sa-select v-model="searchForm.status" dict="audits" placeholder="请选择审核状态" />
          </a-form-item>
		  
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
	<audit-form ref="auditRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import auditForm from './audit.vue'
import api from '../api/reservation'

// 引用定义
const crudRef = ref()
const editRef = ref()
const auditRef=ref()
const activeTab = ref('zh') // 默认选中中文
// 搜索表单
const searchForm = ref({
  project_id: '',
  reservation_person: '',
  id_number: '',
  phone_number: '',
  reservation_time: '',
  status: '',
})


// SaTable 基础配置
const options = reactive({
  api: (params) => api.getPageList({ ...params, ...searchForm.value }),
  pk: 'reservation_id',
  rowSelection: { showCheckedAll: true },
  add: {
    show: false,
    auth: ['/reservation/reservation/save'],
    func: async () => {
      const currentLangCode = searchForm.value.lang_code;
      editRef.value?.open()
      editRef.value?.setFormData({lang_code:currentLangCode})
    },
  },
  edit: {
    show: true,
    auth: ['/reservation/reservation/update'],
    func: async (record) => {
      auditRef.value?.open('edit')
      auditRef.value?.setFormData(record)
    },
	 text:'审核'
	
  },
  delete: {
    show: false,
    auth: ['/reservation/reservation/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
  },
   export: { show: true, url: '/reservation/reservation/export', auth: ['/reservation/reservation/export'] },
})

// SaTable 列配置
const columns = reactive([
  { title: '预约项目', dataIndex: 'project_id_text', width: 180 },
  { title: '预约时段', dataIndex: 'reservation_time_slot', width: 180 },
  { title: '预约人', dataIndex: 'reservation_person', width: 180 },
  { title: '身份证号', dataIndex: 'id_number', width: 180 },
  { title: '手机号', dataIndex: 'phone_number', width: 180 },
  { title: '预约人数', dataIndex: 'reservation_number', width: 180 },
  { title: '预约时间', dataIndex: 'reservation_time_text', width: 180 },
  { title: '审核状态', dataIndex: 'status_text', width: 180 },
])

// 页面数据初始化
const initPage = async () => {
    searchForm.value.lang_code='zh'
}
const handleTabChange = async (key) => {
   activeTab.value = key
   // 设置语言代码
   searchForm.value.lang_code = key
   // 刷新表格数据
   crudRef.value?.refresh()
}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
